/**
Copyright [2008] [Julian Gamble] 

Licensed under the Apache License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

	http://www.apache.org/licenses/LICENSE-2.0 
	
Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License. 
 **/
package aerith.swing;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.border.CompoundBorder;
import javax.swing.plaf.basic.BasicComboBoxRenderer;

public class AerithComboBox extends JComboBox {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1210500744350035012L;

	private Color inputColor = new Color(70, 70, 70), // background colour
			inputBorderColor = new Color(220, 220, 220),
			inputTextColor = new Color(255, 255, 255);

	private Font inputFont = new Font("Default", Font.BOLD, 24);

	public AerithComboBox() {
		super();

		setOpaque(true);

		setBackground(inputColor);

		setBorder(new CompoundBorder(BorderFactory.createLineBorder(
				inputBorderColor, 2), BorderFactory.createEmptyBorder(2, 2, 2,
				2)));

		setForeground(inputTextColor);
		setFont(inputFont);

		// ListCellRenderer cr = getRenderer();

		/*ComboBoxEditor editor = getEditor();
		if (editor != null) {
			Component editorComp = editor.getEditorComponent();
			if (editorComp instanceof JComponent) {
				JComponent editorJComp = (JComponent) editorComp;
				editorJComp.setForeground(inputTextColor);
				editorJComp.setBackground(inputColor);
				editorJComp.setBorder(new CompoundBorder(BorderFactory
						.createLineBorder(inputBorderColor, 2), BorderFactory
						.createEmptyBorder(2, 2, 2, 2)));
			}
			this.setEditor(editor);
		}*/
		setRenderer(new MyRenderer());
	}

	/*
	 * public ListCellRenderer getRenderer() { setBackground(inputColor);
	 * 
	 * return super.getRenderer(); }
	 */

	/*
	 * public void paint(Graphics g) { super.paint(g);
	 * setBackground(inputColor);
	 * 
	 * setBorder(new CompoundBorder(BorderFactory.createLineBorder(
	 * inputBorderColor, 2), BorderFactory.createEmptyBorder(2, 2, 2, 2)));
	 * 
	 * setForeground(inputTextColor); setFont(inputFont);
	 * 
	 * ComboBoxEditor editor = getEditor(); if (editor != null) { Component
	 * editorComp = editor.getEditorComponent(); if (editorComp instanceof
	 * JComponent) { JComponent editorJComp = (JComponent) editorComp;
	 * editorJComp.setForeground(inputTextColor);
	 * editorJComp.setBackground(inputColor); editorJComp.setBorder(new
	 * CompoundBorder(BorderFactory.createLineBorder( inputBorderColor, 2),
	 * BorderFactory.createEmptyBorder(2, 2, 2, 2))); } this.setEditor(editor); } }
	 */
	class MyRenderer extends BasicComboBoxRenderer {
		/**
		 * 
		 */
		private static final long serialVersionUID = -4873608078177499693L;

		public MyRenderer() {
			super();
			setBorder(new CompoundBorder(BorderFactory.createLineBorder(
					inputBorderColor, 2), BorderFactory.createEmptyBorder(2, 2, 2,
					2)));
		}
		
		public Component getListCellRendererComponent(JList list, Object value,
				int index, boolean isSelected, boolean cellHasFocus) {
			Component component = super.getListCellRendererComponent(list,
					value, index, isSelected, cellHasFocus);
			component.setBackground(inputColor);
			//setBackground(inputColor);
			setBorder(new CompoundBorder(BorderFactory.createLineBorder(
					inputBorderColor, 2), BorderFactory.createEmptyBorder(2, 2, 2,
					2)));

			//setForeground(inputTextColor);
			return component;
		}
	}

}
